Audio Data Blocks

The waveInAddBuffer76989G and waveOutWrite12C9KIJ functions require applications to allocate data blocks to pass to the device drivers for recording or playback purposes. Both of these functions use the WAVEHDR3CAL0JU structure to describe its data block.

Before using one of these functions to pass a data block to a device driver, you must allocate memory for the data block and the header structure that describes the data block. The headers can be prepared and unprepared by using the following functions.

Function

Description

waveInPrepareHeaderB61UY8

Prepares a waveform-audio input data block.

waveInUnprepareHeader_ZZ.W6

Cleans up the preparation on a waveform-audio input data block.

waveOutPrepareHeader1MF2IJO

Prepares a waveform-audio output data block.

waveOutUnprepareHeader7UH.0HU

Cleans up the preparation on a waveform-audio output data block.

 

Before you pass an audio data block to a device driver, you must prepare the data block by passing it to either waveInPrepareHeaderB61UY8 or waveOutPrepareHeader1MF2IJO. When the device driver is finished with the data block and returns it, you must clean up this preparation by passing the data block to either waveInUnprepareHeader_ZZ.W6 or waveOutUnprepareHeader7UH.0HU before any allocated memory can be freed.

Unless the waveform-audio input and output data is small enough to be contained in a single data block, applications must continually supply the device driver with data blocks until playback or recording is complete.

Even if a single data block is used, an application must be able to determine when a device driver is finished with the data block so the application can free the memory associated with the data block and header structure. There are several ways to determine when a device driver is finished with a data block:

    By specifying a callback function to receive a message sent by the driver when it is finished with a data block

    By using an event callback

    By specifying a window or thread to receive a message sent by the driver when it is finished with a data block

    By polling the WHDR_DONE bit in the dwFlags member of the WAVEHDR3CAL0JU structure sent with each data block

 

If an application does not get a data block to the device driver when needed, there can be an audible gap in playback or a loss of incoming recorded information. This requires at least a double-buffering scheme   staying at least one data block ahead of the device driver.

The following sections describe ways to determine when a device driver is finished with a data block:

    Using a callback function to process driver messages1175GV3

    Using an event callback to process driver messages1GHS73W

    Using a window or thread to process driver messages37R66GD

    Managing data blocks by polling2E06097